package com.xxxx

import org.apache.flink.configuration.Configuration
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}

object WordCountStreamingByScala {
  def main(args: Array[String]): Unit = {
    //获取环境
    val environment: StreamExecutionEnvironment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
    //获取数据源
    val source: DataStream[String] = environment.socketTextStream("localhost", 18880);
    //开始转换
    import org.apache.flink.api.scala._;
    source.flatMap(_.split(" ")).map((_, 1)).keyBy(0).sum(1).print;
    //开启流式处理
    environment.execute("WordCountStreamingByScala" + System.currentTimeMillis());
  }
}
